
(function(window){
	
	var  document = window.document,
	     location = window.location,
	     navigator = window.navigator,

	// Map over jQuery in case of overwrite
	_jQuery = window.jQuery,

	// Map over the $ in case of overwrite
	_$ = window.$;
	
		
    var toolsFn={
    		
    		hereDoc:function (doc,ref) {
    			/*	
    			alert(hodc.toString())
    			alert(hodc.toString().split("/*"))
    			alert(hodc.toString().split("/*")[1])
    			 */
    			return doc.toString().split("/*")[1].split("*/")[0].replace(
    					/\$\{([^}]+)\}/g, function(outer, inner, pos) {
    						return dynAttrValue(ref, inner);
    					})

    		},
    		
    		dynAttrValue:function (variable, key) {

    			var attrs = key.split("\.");

    			for (var i = 0; i < attrs.length; i++) {

    				if (i == 0) {
    					value = variable[attrs[0]]
    				} else {
    					value = value[attrs[i]]
    				}

    			}

    			return value;

    		}
    		,
    		
    		arrayContains:function (array, obj) {
    		    var i = a.length;
    		    while (i--) {
    		       if (array[i] === obj) {
    		           return true;
    		       }
    		    }
    		    return false;
    		}	,
    		/*
    		模拟 form post 做 js post 提交
    		*/
    		formPost:function (URL, PARAMS,form_target) {        
    		    var form = document.createElement("form");        
    		    form.action = URL;        
    		    form.method = "post";        
    		    form.style.display = "none";     
    		    if(form_target){
    		    	form.target=form_target;    	
    		    }
    		    for (var x in PARAMS) {        
    		        var opt = document.createElement("input");        
    		        opt.name = x;        
    		        opt.value = PARAMS[x];        
    		        // alert(opt.name)        
    		        form.appendChild(opt);        
    		    }        
    		    document.body.appendChild(form);        
    		    form.submit();        
    		    return temp;        
    		}    ,


    		/*
    		获得 url 上的参数 封装成 json对象
    		*/
    		getUrlParams:function (){

    		var locationurl = location.href;
    		var  tem0= locationurl.split("#");

    		var tem = tem0[0].split('?');
    		var paramsdata = {};

    		if (tem.length > 1) {

    			var parms = tem[1].split('&');

    			for ( var i = 0; i < parms.length; i++) {

    				var param = parms[i].split('=');

    					paramsdata[param[0]] = param[1];
    			}
    		}

    		return paramsdata;

    		},


    		/*
    		值转换
    		*/
    		valueMapping:function (value,mapping){
    			var res="";
    			if(value){
    			 res= mapping[value];
    			}
    			
    			 return  res;
    			 
    		},


    		/*
    		去除 undfine null
    		*/
    		fitValue:function (value){
    			
    			if(value){
    				
    			}else{
    			value="";
    			}
    			
    			return value;
    			
    		},
    		
    		getformElementParams: function(container, isall) {

    			var param = {};

    			var inputs = container.find('input');

    			var selects = container.find('select');

    			var textareas = container.find('textarea');
    			
    			for ( var i in inputs) {
    				if (!isNaN(i)) {

    					var input = inputs[i];

    					if((input.name&&input.name!==""&&input.name!=="id")||(input.value&&input.value!==""&&input.name=="id")){
    						if(isall){
            					param[input.name] = input.value!=""?input.value:null;
    						}else{
    							if(input.value =="" || input.value == null){
    								continue;
    							}
    							param[input.name] = input.value!=""?input.value:null;
    						}
        					
        					
        				}

    					
    				}

    			}
    			
    			
    			for ( var i in textareas) {
    				if (!isNaN(i)) {

    					var textarea = textareas[i];

    					if(textarea.value&&textarea.value!==""){
	    					if(isall){
	    						param[textarea.name] = textarea.value;
							}else{
								if(textarea.value =="" || textarea.value == null){
									continue;
								}
								param[textarea.name] = textarea.value;
							}
    					}
    				}

    			}
    		
    			for ( var i in selects) {
    				if (!isNaN(i)) {

    					var select = selects[i];

    					 var value=$(select).val();
    					
    					if(value&&value!==""){
    					
	    					if(isall){
	    						param[select.name] = value;
							}else{
								if(value =="" || value == null){
									continue;
								}
								param[select.name] = value;
							}
    					}
    					
    				}

    			}

    			return param;

    		} , 
    		
    		
    		setformElementParams:function test(container,param){
    			 
    			 var inputs=container.find('input');
    			 var selects = container.find('select');
    		     var textareas = container.find('textarea');
    			
    			 	for ( var i in inputs) {
    		    				if (!isNaN(i)) {
    		                     	var input = inputs[i];
    		                     	var name=input.name;
    		    					if(name&&name!=="" && param[name]!=undefined){
    		                     	input.value=param[name]
    		    					}
    		    				}

    		    			}
    			 	
    			 	for ( var i in textareas) {
    					if (!isNaN(i)) {
    						var textarea = textareas[i];
    						var name=textarea.name;
    						if(name&&name!==""){
                                var content = param[name];
                                if(content == null || content== '' || content=='null' ){
                                    textarea.value = '';
								}else{
                                    textarea.value=param[name]  ;
								}

    						}
    					}

    				}
    			
    				for ( var i in selects) {
    					if (!isNaN(i)) {

    						var select = selects[i];

    						var name=select.name
    						
    						 var value=$(select).val();
    						
    						if(name&&name!==""){
    						$(select).val( param[name]) ;
    						}
    						
    					}

    				}
    			 
    			 
    		 },
    		 isEmptyObject:function (obj){
    			  for(var key in obj){
    			          return false
    			     };
    			     return true
    		 },
    		pagedownReady: function(aLink,fileName){
   
    			 var content = document.getElementsByTagName("html")[0].outerHTML;
    	 
    			 if (navigator.userAgent.indexOf('Firefox') >= 0) {
    					var blob = new Blob([ content ]);
    					var evt = document.createEvent("HTMLEvents");
    					evt.initEvent("click", false, false);

    					aLink.download = fileName;
    					aLink.href = URL.createObjectURL(blob);
    					aLink.dispatchEvent(evt);
    				  document.getElementById("a").click();
    				}
    				else if ((navigator.userAgent.indexOf('MSIE') >= 0)
    						&& (navigator.userAgent.indexOf('Opera') < 0)
    						|| (!!window.ActiveXObject || "ActiveXObject" in window)
    						|| (navigator.userAgent.indexOf('Edge') >= 0)) {
    				
    				} 
    				else {
    					var blob = new Blob([ content ]);
    					var evt = document.createEvent("HTMLEvents");
    					evt.initEvent("click", false, false);
    					aLink.download = fileName;
    					aLink.href = URL.createObjectURL(blob);
    					aLink.dispatchEvent(evt);
    				//document.getElementById("a").click();
    				}
    			
    			}

    			,
    			 pagedownIE:function() {

    			if ((navigator.userAgent.indexOf('MSIE') >= 0)
    						&& (navigator.userAgent.indexOf('Opera') < 0)
    						|| (!!window.ActiveXObject || "ActiveXObject" in window)
    						|| (navigator.userAgent.indexOf('Edge') >= 0)) {
    				document.execCommand('Saveas', false, 'c:\\' + fileName);
    				} 

    			},
    			getWindowWH:function(){
    				var winWidth;
    				var winHeight;
    			if (window.innerWidth)
    				winWidth = window.innerWidth;
    				else if ((document.body) && (document.body.clientWidth))
    				winWidth = document.body.clientWidth;
    				// 获取窗口高度
    				if (window.innerHeight)
    				winHeight = window.innerHeight;
    				else if ((document.body) && (document.body.clientHeight))
    				winHeight = document.body.clientHeight;
    				// 通过深入 Document 内部对 body 进行检测，获取窗口大小
    				if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
    				{
    				winHeight = document.documentElement.clientHeight;
    				winWidth = document.documentElement.clientWidth;
    				}

    				return {'winHeight':winHeight,'winWidth':winWidth};

    			}
    			
    			
    			
		};
    
    
   
    /*
    !important  构造方法传字符串   中国式身份证处理对象
    */
    window.Idcard=function(idNo,local) {
    	
   	this.idNo = idNo;
   	
if(local=="zh_CN"||local=="CN"||local=="zh"||local==undefined){
   	
   		this.getBirthday = function() {
   	   		   		var birthdayno, birthdaytemp;
   	   		   		if (this.idNo.length == 18) {
   	   		   			birthdayno = this.idNo.substring(6, 14);
   	   		   		} else if (this.idNo.length == 15) {
   	   		   			birthdaytemp = psidno.substring(6, 12);
   	   		   			birthdayno = "19" + birthdaytemp;
   	   		   		} else {
   	   		   			return false;
   	   		   		}
   	   		   		
   	   		   		
   	   		   		var birthday=new Date();
   	   		   		
   	   		   		birthday.setFullYear(birthdayno.substring(0, 4), birthdayno.substring(4, 6)-1, birthdayno.substring(6, 8));
   	   		   		
   	   		   		return birthday;
   	   		   	};

   	   		this.getSex = function() {
   	   		   		var sexno, sex;
   	   		   		if (this.idNo.length == 18) {
   	   		   			sexno = this.idNo.substring(16, 17);
   	   		   		} else if (this.idNo.length == 15) {
   	   		   			sexno = this.idNo.substring(14, 15);
   	   		   		} else {
   	   		   			alert("错误的身份证号码，请核对！");
   	   		   			return false;
   	   		   		}
   	   		   		var tempid = sexno % 2;
   	   		   		if (tempid == 0) {
   	   		   			sex = 'F';
   	   		   		} else {
   	   		   			sex = 'M';
   	   		   		}
   	   		   		return sex;
   	   		   	};

   	   		this.getProvinceNameByIdNo = function() {
   	   		   		var area = {11 : "北京",12 : "天津",13 : "河北",14 : "山西",15 : "内蒙古",21 : "辽宁",
   	   		   			22 : "吉林",23 : "黑龙江",31 : "上海",32 : "江苏",33 : "浙江",34 : "安徽",
   	   		   			35 : "福建",36 : "江西",37 : "山东",41 : "河南",42 : "湖北",43 : "湖南",
   	   		   			44 : "广东",45 : "广西",46 : "海南",50 : "重庆",51 : "四川",52 : "贵州",
   	   		   			53 : "云南",54 : "西藏",61 : "陕西",62 : "甘肃",63 : "青海",
   	   		   			64 : "宁夏",65 : "新疆",71 : "台湾",81 : "香港",82 : "澳门",91 : "国外"
   	   		   		};

   	   		   		var provinceName = "";
   	   		   		var provinceNo = this.idNo.substr(0, 2);
   	   		   		if (area[parseInt(provinceNo)] != null) {
   	   		   			provinceName = area[parseInt(provinceNo)];
   	   		   		}
   	   		   		return provinceName;
   	   		   	};

   	   		this.idCheck=function(){
   	   		   		var idPat=new RegExp(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/);
   	   		   		
   	   		   		if (!idPat.test(this.idNo)) {
   	   		   			alert("请输入正确的身份证号");
   	   		   			return false;
   	   		   		} 
   	   		   		return true;
   	   		   	};
   	   		   	
   	    	
   	   };
   	  
    };

   
   Date.prototype.format = function (fmt) { 
	    var o = {
	        "M+": this.getMonth() + 1, //月份 
	        "d+": this.getDate(), //日 
	        "h+": this.getHours(), //小时 
	        "m+": this.getMinutes(), //分 
	        "s+": this.getSeconds(), //秒 
	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
	        "S": this.getMilliseconds() //毫秒 
	    };
	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	    for (var k in o)
	    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	    return fmt;
	};
    
    
  

	if(_jQuery!=undefined&&_$!=undefined&&_jQuery==_$){
			
		$.extend(toolsFn);
	
	}else{
		
		  window.tF=toolsFn;
		
	}
    
    

}(window));




function menuSelect(indices){

	var root = $("#menu_ul").children("li");

	var indexes = indices.split(",");
	if(indexes.length > 1){
		var liDom = $("#"+indexes[0]);
		liDom.addClass("nav-active");
		var target_li = $("#"+indexes[1]);
		target_li.addClass("active");
        /*var collpse_index = indexes[0];
        for(var key = 0 ;key <  root.length; key++){
            var liDom = $(root[key]);
            if(key == collpse_index){
                liDom.addClass("nav-active");
                var target_li_arr = liDom.children("ul[class='sub-menu-list']").children("li");
				for(var i=0 ; i < target_li_arr.length ; i++){
					if(indexes[1] == i){
                        $(target_li_arr[i]).addClass("active");
					}
				}
            }
        }*/
	}else{
		var liDom = $("#" + indices);
		liDom.addClass("active");
    	/*var index = indexes[0];
    	for(var key = 0 ;key <  root.length; key++){
            var liDom = $(root[key]);
            if(key == index){
                liDom.addClass("active");
            }
		}*/
	}
}







function compareForDay(current , after){
    if(current.getFullYear() < after.getFullYear()){
        return  -1;
    }
    if(current.getMonth() < after.getMonth() ){
        return -1;
    }
    if(current.getMonth() > after.getMonth() ){
        return 1;
    }
    if(current.getDate()  < after.getDate() ){
        return -1;
    };
    return 1;

}



function hereDoc(doc, ref) {
	return doc.toString().split("/*")[1].split("*/")[0].replace(
			/\$\{([^}]+)\}/g, function(outer, inner, pos) {

				return dynAttrValue(ref, inner);
			})
}

function dynAttrValue(variable, key) {
	var attrs = key.split("\.");
	for (var i = 0; i < attrs.length; i++) {

		if (i == 0) {
			value = variable[attrs[0]]
		} else {
			value = value[attrs[i]]
		}
	}

	return value;

}








var indexSet = {

	indexcode : [],
	toString : function() {

		return this.indexcode.toString();
	},

	put : function(index) {
		this.indexcode.push(index);
	},

	del : function(index) {

		for (var i = 0; i < this.indexcode.length; i++) {

			if (this.indexcode[i] == index) {

				if (i == this.indexcode.length - 1) {
					this.indexcode.pop();
				} else {

					var tem = this.indexcode[i];

					this.indexcode[i] = this.indexcode[this.indexcode.length - 1];
					this.indexcode[this.indexcode.length - 1] = tem;
					this.indexcode.pop();

				}

			}

		}

	},
	contains : function(index) {

		for (var i = 0; i < this.indexcode.length; i++) {

			if (this.indexcode[i] == index) {

				return true;
			}

		}

		return false;

	}

};

function conformModal(text,eventname) {
	var v = {
		'alert' : text,
		'eventfun':eventname
	};

	var modaltext = hereDoc(function() {
		/*
		  <div class="modal" id="alert"> <div class="modal-dialog"
		  style="width:400px;"> <div class="modal-content"> <div
		  class="modal-header"> <button type="button" class="close"
		  data-dismiss="modal" aria-label="Close"><span
		  aria-hidden="true">&times;</span></button> <h4 class="modal-title">提示</h4>
		  </div> <div class="modal-body"> <div id="btneMsg">${alert}</div>
		  </div> <div class="modal-footer"> 
		  <button type="button" class="btn btn-warning" data-dismiss="modal"  onClick='${eventfun}()'  >确 认</button> 
		  <button type="button" class="btn btn-primary" data-dismiss="modal"    >取消</button>
		  </div> 
		  </div> 
		  </div>
		  </div>
		 */
	}, v)

	$(modaltext).modal({
		keyboard : true
	});
}

function alertModal(text,onConfirm) {

	if(onConfirm){
		onConfirm=onConfirm+'()';
	}else{
		onConfirm='';
	}
	
	
	var v = {
		'alert' : text,
		'onConfirm':onConfirm
	};

	var modaltext = hereDoc(function() {
		/*
		  <div class="modal" id="alert"> <div class="modal-dialog"
		  style="width:400px;"> <div class="modal-content"> <div
		  class="modal-header"> <button type="button" class="close"
		  data-dismiss="modal" aria-label="Close"><span
		  aria-hidden="true">&times;</span></button> <h4 class="modal-title">提示</h4>
		  </div> <div class="modal-body"> <div id="btneMsg" style="word-wrap:break-word">${alert}</div>
		  </div> <div class="modal-footer"> <button type="button" class="btn
		  btn-default"   onclick="${onConfirm}"  data-dismiss="modal">确 认</button> </div> </div> </div>
		  </div>
		 */
	}, v)

	$(modaltext).modal({
		keyboard : true
	});
}

function guid() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
        return v.toString(16);
    });
}
